using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.RuleTile.TilingRuleOutput;

public class SkeletonMoveState : SkeletonGroundedState
{
    public SkeletonMoveState(Enemy _enemyBase, EnemyStateMachine _stateMachine, string _animBoolName, Enemy_Skeleton enemy) : base(_enemyBase, _stateMachine, _animBoolName, enemy)
    {
    }

    public override void Enter()
    {
        base.Enter();

        Debug.Log("Move");
    }

    public override void Exit()
    {
        base.Exit();
    }

    public override void Update()
    {
        base.Update();

        enemy.SetVelocity(enemy.moveSpeed * enemy.facingDir, enemy.rb.velocity.y);

        if (Vector2.Distance(enemy.originaPos, enemy.transform.position) < 0.5)
            enemy.isReturn = false;

        if (enemy.IsWallDetected() || !enemy.IsGroundDetected() || (!enemy.IsInMoveRange() && !enemy.isReturn)) 
        {
            enemy.Flip();
            enemy.isReturn = true;
            stateMachine.ChangeState(enemy.idleState);
        }
    }
}
